
from my import *
from .utils import *

toolname = getToolName()

import sys
import pyperclip as pc
from pathlib import Path
from enum import Enum
import optparse


def func(isHelp=False):
    if(isHelp):
        return [toolname,"~ %s -f file"%(toolname),"=excel | table","-h"]
    argv = getToolArgv()
    parser = optparse.OptionParser("")
    parser.add_option("-f",  '--filepath', dest="filePath", default = "x")
    parser.add_option("-i",  '--sheetindex', dest="sheetIndex", default = 0)
    options, args = parser.parse_args()
    filePath = options.filePath 
    if(filePath == "x"): 
        print("use -f")
        return 
    sheetObject = None
#   breakpoint()
    if(filePath.split('.')[-1] == 'xls'):
        import xlrd as xl # type: ignore
        sheetObject = xl.open_workbook(Path(filePath))
    elif(filePath.split('.')[-1] == 'xlsx'):
        import openpyxl as xl # type: ignore
        sheetObject = xl.load_workbook(Path(filePath))
    if(not sheetObject):
        print('.xls | .xlsx')
        return  
    sheetList=sheetObject.worksheets
    sheet=sheetObject[sheetList[options.sheetIndex].title]
    for row in sheet.values:
        for colmnnum in range(len(row)):
            print(str(row[colmnnum]).replace("\n","\\n"),end='\t')
        print()

